import * as dataUtil from '@/utils/index'
import * as $api from '@/http/request-axios';
export default {
	props: {
		queryApi: {
			type: String,
			default: ''
		},
		removeApi: {
			type: String,
			default: ''
		},
		userParams: {
			type: Object,
			default: () => {}
		},
		requestComplete: {
			type: Function,
			default: () => {}
		},
		value: {
			type: Array,
			default: () => {
				return [];
			}
		}
	},
	data() {
		return {
			total: 0,
			totalPages: 0,
			loading: false,
			eventKey: '',
			tableData: this.value,
			hasPreviousPage: false,
			hasNextPage: false,
			isPageData: true,
			loadParams: this.userParams,
			params: {
				pageIndex: 1,
				pageSize: this.pageSize,
				search: ""
			}
		}
	},
	computed: {

	},
	methods: {
		async getPage() {
			if (this.queryApi != "") {
				this.loading = true;
				var apiParams = {};
				dataUtil.copyValue(apiParams, this.params, {
					inNull: true
				});
				dataUtil.copyValue(apiParams, this.loadParams, {
					inNull: true
				});
				var pageReult = await $api.http(this.queryApi, apiParams);
				if (pageReult != null) {
					this.tableData = pageReult.List;
					this.total = pageReult.TotalCount;
					this.totalPages = pageReult.TotalPages;
					this.hasPreviousPage = pageReult.HasPreviousPage;
					this.hasNextPage = pageReult.HasNextPage;
					this.loading = false;
					this.requestComplete(pageReult);
				}
			}
		},
		refresh() {
			this.params.pageIndex = 1;
			this.total = 0;
			this.getPage();
		},
		reload(ps) {
			this.params.pageIndex = 1;
			this.total = 0;
			dataUtil.copyValue(this.params, ps, {
				inNull: true
			});
			this.getPage();
		},
		refreshCurrentPage(ps) {
			this.total = 0;
			dataUtil.copyValue(this.params, ps, {
				inNull: true
			});
			this.getPage();
		},
		currentChange(val) {
			this.params.pageIndex = val;
			this.getPage();
		},
		handleSizeChange(val) {
			this.params.pageIndex = 1;
			this.params.pageSize = val;
			this.total = 0;
			this.getPage();
		},
		searchClick(query) {
			this.params.pageIndex = 1;
			this.total = 0;
			this.getPage();
		},
		showIndex(index) {
			return (index + 1 + this.params.pageSize * (this.params.pageIndex - 1));
		},
		edit(data) {

		},
		async remove(data, flag) {
			var $this = this;
			var remove = async () => {
				await $api.http($this.removeApi, {
					Id: data.Id
				});
				$this.reload();
			};
			$this.$confirm(((flag.command == null || flag.command.message == null) ? '此操作将永久删除, 是否继续?' : flag
				.command.message), '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				remove();
			}).catch(() => {

			});
		},
		userStyle(row) {
			var color = "#333";
			if (row.TaskInfo) {
				switch (row.TaskInfo.Type) {
					case -1: // 终止申请
						color = "#121a2a";
						break;
					case 2: // 未审核
						color = "#6000D8";
						break;
					case 3: // 审核未通过
						color = "#007AD8";
						break;
					case 4: // 提交申请材料
						color = "#00D88F";
						break;
					case 5: // 提交申请材料
						color = "#6000D8";
						break;
					case 6: // 
						color = "#FF7287";
						break;
					case 7: // 提交申请材料
						color = "#FF2A49";
						break;
					case 8: // 立案确认函审核
						color = "#6000D8";
						break;
					case 9: // 编辑立案确认函
						color = "#FF7287";
						break;
					case 10: // 待上传委托书
						color = "#FF420C";
						break;
					case 11: // 待上传委托书
						color = "#0A1BCE";
						break;
					case 12: // 待官方受理
						color = "#DA007A";
						break;
					case 13: // 官方审查中
						color = "#0097CC";
						break;
					case 14: // 待官方受理
						color = "#FF3533";
						break;
					case 15: // 官方申请结束
						color = "#0067FF";
						break;
					case 16: // 专利维护中
						color = "#FF9469";
						break;
				}
			}
			return {
				color: color
			};
		}
	},
	mounted() {
		this.getPage();
	}
}